package s05;

import net.sf.cglib.proxy.*;

import java.lang.reflect.Method;

/**
 * @author wangpp
 */
public class MyCallBackHelper extends CallbackHelper {

    public MyCallBackHelper(Class superclass) {
        super(superclass, new Class[0]);
    }

    public MyCallBackHelper(Class superclass, Class[] interfaces) {
        super(superclass, interfaces);
    }

    /**
     * 过滤方法
     *
     * @param method
     * @return
     */
    @Override
    protected Object getCallback(Method method) {
        if (method.getReturnType() == String.class) {
            return new FixedValue() {
                @Override
                public Object loadObject() throws Exception {
                    return "hello filter fix value";
                }
            };
        } else if (method.getReturnType() == Integer.class) {
            return new FixedValue() {
                @Override
                public Object loadObject() throws Exception {
                    return 9999;
                }
            };
        } else if (method.getReturnType() == Long.class) {
            return new MethodInterceptor() {
                @Override
                public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                    System.out.println("before looooooooooooooooooooog");
                    return proxy.invokeSuper(obj, args);
                }
            };
        }
        return NoOp.INSTANCE;
    }
}
